#include <iostream>
#include <cstring>

using namespace std;

int MAX(int a, int b){
	return a>b?a:b;
}

int MIN(int a, int b){
	return a<b?a:b;
}

int main(){
	int n;
	cin >> n;
	int arrA[1001];
	int arrB[1001];
	for(int i = 1; i <= n; i++)
		cin >> arrA[i];
	for(int i = 1; i <= n; i++)
		cin >> arrB[i];
	int table[101][1001];
	memset(table, -1, sizeof(table));
	table[0][0] = 0;
	int maxx = 0;
	for(int k = 1; k <= n; k++){
		maxx += arrA[k];
		for(int x = 0; x <= maxx; x++){
			if(table[k-1][x] == -1) continue;
			table[k][x] = table[k-1][x] + arrB[k];
			table[k][x+arrA[k]] = table[k - 1][x];
		}
	}
	int min;
	memset(&min, 0x7f, sizeof(int));
	for(int i = 0; i <= maxx; i++){
		if(table[n][i] == -1) continue;
		if(min > MAX(i , table[n][i])) min = MAX(i, table[n][i]);
	}
	cout << min << endl;
}

